<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24" >
            <a-form-model-item label="井id号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jingId" v-show="isadd===true" >
              <a-input v-model="model.jingId" placeholder="请输入井id号"v-show="isadd===true" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地理位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dlwz">
              <a-input v-model="model.dlwz" placeholder="请输入地理位置"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="构造位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gzwz">
              <a-input v-model="model.gzwz" placeholder="请输入构造位置"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地面海拔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dmhb">
              <a-input v-model="model.dmhb" placeholder="请输入地面海拔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开钻日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kzrq">
              <j-date placeholder="请选择开钻日期" v-model="model.kzrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="完钻井深" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wzjs">
              <a-input v-model="model.wzjs" placeholder="请输入完钻井深"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人工井底" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rgjd">
              <a-input v-model="model.rgjd" placeholder="请输入人工井底"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最大井斜" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zdjx">
              <a-input v-model="model.zdjx" placeholder="请输入最大井斜"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="油层套管清水控制压力" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yctgqskzyl">
              <a-input v-model="model.yctgqskzyl" placeholder="请输入油层套管清水控制压力"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="补心海拔" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bxhb">
              <a-input v-model="model.bxhb" placeholder="请输入补心海拔"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="完钻日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wzrq">
              <j-date placeholder="请选择完钻日期" v-model="model.wzrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="完钻层位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wzcw">
              <a-input v-model="model.wzcw" placeholder="请输入完钻层位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="完井方法" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wjff">
              <a-input v-model="model.wjff" placeholder="请输入完井方法"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最大井斜处井深" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zdjxcjs">
              <a-input v-model="model.zdjxcjs" placeholder="请输入最大井斜处井深"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="压裂井口" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yljk">
              <a-input v-model="model.yljk" placeholder="请输入压裂井口"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="井名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jingName">
              <a-input v-model="model.jingName" placeholder="请输入jingName"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'YtsjJdjcxxForm',
    components: {
    },
    props: {
        chuandangqianjingid:{type:Function},
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
          dangqianjingId:{},
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           jingId: [
              { required: true, message: '请输入井id号!'},
           ],
        },
        url: {
          add: "/jdjcxx/ytsjJdjcxx/add",
          edit: "/jdjcxx/ytsjJdjcxx/edit",
          queryById: "/jdjcxx/ytsjJdjcxx/queryById"
        },
          isadd:false
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
      updated(){
          this.total();
      },
    created () {


      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
        total(){
            this.chuandangqianjingid(this.model.jingId)
          console.log(this.model.jingId+"拿到当前井的id了哈哈哈");
          this.dangqianjingId = this.model.jingId;
          localStorage.setItem("jingId",this.dangqianjingId)
            console.log(localStorage.getItem("jingId") +"这是保存下来的井id");

        },
      add () {
        this.edit(this.modelDefault);
        this.isadd =true;
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            // if(!this.model.id){
            //   httpurl+=this.url.add;
            //   method = 'post';
            // }else{
            //   httpurl+=this.url.edit;
            //    method = 'put';
            // }
              if (this.isadd){
                  httpurl+=this.url.add;
                  method = 'post';
                  // this.isxianshi = false;
              }else {
                  httpurl+=this.url.edit;
                  method = 'put';
              }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              this.isadd = false
            })
          }
         
        })
      },
    }
  }
</script>